<!-- views/Home.vue -->
<template>
  <div class="app-container">
    <div class="button-container">
      <button class="plus-button" @click="increment">+ 增加盒子</button>
      <button class="minus-button" @click="decrement">- 减少盒子</button>
    </div>
    <div class="green-area">
      <div
          v-for="(item, index) in boxList"
          :key="index"
          @click="goToPage(index)"
          class="box-item"
      >
        盒子 {{ index + 1 }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const boxList = ref([...Array(5)]);

const increment = () => {
  boxList.value.push({});
};

const decrement = () => {
  if (boxList.value.length > 0) {
    boxList.value.pop();
  }
};

const goToPage = (index) => {
  router.push({ name: 'Page', params: { id: index } });
};
</script>


<style scoped lang="scss">
.app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

.button-container {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.plus-button {
  padding: 10px 20px;
  background-color: #4285f4;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;

  &:hover {
    background-color: #337aff;
  }
}

.minus-button {
  padding: 10px 20px;
  background-color: #ea4335;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;

  &:hover {
    background-color: #dd3a2e;
  }
}

.green-area {
  background-color: #d1f1d8;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.box-item {
  background-color: white;
  /* 调整盒子尺寸 */
  height: 80px;
  width: 160px;
  padding: 20px;
  border-radius: 15px; /* 增大边框圆角 */
  border: 1px solid #e0e0e0;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease;

  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  }
}
</style>